package org.legocam.actions;

import org.legocam.Camera;
import org.legocam.UIStrings;

public class TakePicture implements Runnable
{
private final Camera camera;
	
	public TakePicture(Camera camera)
	{
		this.camera = camera;
	}

	public void run()
	{
		camera.setShutterOpen( true );
		sleep();
		camera.setShutterOpen( false );
		
		camera.advanceOneFrame();
		
		camera.saveSettings();
		camera.updateCameraStatus();
	}

	private void sleep()
	{
		final long totalSeconds = camera.getShutterTime()/1000;
		
		for ( int i = 0; i < totalSeconds; i++ )
		{
			camera.printMainMessage( (totalSeconds - i) + UIStrings.TEXT_SECONDS_LEFT);
			
			try
			{
				Thread.sleep( 500 );
			}
			catch (InterruptedException e) {}
		}
	}
}
